if not ( RES_DISTRIB == 2 ) then Error("Please Install Resource Distribution 2 Addon.'" ) return end

TOOL.Category = '(Food Mod)'
TOOL.Name = '#Beer Generators'
TOOL.Command = nil
TOOL.ConfigName = ''
if (CLIENT and GetConVarNumber("RD_UseLSTab") == 1) then TOOL.Tab = "Life Support" end

TOOL.ClientConVar['type'] = 'hops_extractor'
TOOL.ClientConVar['model'] = 'models/Gibs/airboat_broken_engine.mdl'

cleanup.Register('beergens')

if ( CLIENT ) then
	language.Add( 'Tool_beergens_name', 'Beer Generators' )
	language.Add( 'Tool_beergens_desc', 'Create Generator attached to any surface.' )
	language.Add( 'Tool_beergens_0', 'Left-Click: Spawn a Device.  Right-Click: Repair Device.' )

	language.Add( 'Undone_beergens', 'Generator Undone' )
	language.Add( 'Cleanup_beergens', 'Beer Generators' )
	language.Add( 'Cleaned_beergens', 'Cleaned up all Beer Generators' )
	language.Add( 'SBoxLimit_foodmod', 'Maximum Foodmod Reached. Too Bad.' )
end

local beergens = {}
if (SERVER) then
	beergens.hops_extractor = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "hops", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.barley_extractor = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "barley", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.huge_barley_extractor = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 10000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "barley", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.yeast_gatherer = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "yeast", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.large_yeast_gatherer = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "yeast", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.large_barley_extractor = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "barley", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.large_malter = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "malt", 0)
		RD_AddResource(ent, "barley", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.large_hops_extractor = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "hops", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.resource_extractor = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "yeast", 0)
		RD_AddResource(ent, "hops", 0)
		RD_AddResource(ent, "barley", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.malter = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 1000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "malt", 0)
		RD_AddResource(ent, "barley", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

	beergens.huge_malter = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 10000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "malt", 0)
		RD_AddResource(ent, "barley", 0)
		LS_RegisterEnt(ent, "Generator")
		return {}, maxhealth, mass
	end

       beergens.beer_generator = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 2000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "water", 0)
		RD_AddResource(ent, "beer", 0)
		RD_AddResource(ent, "hops", 0)
		RD_AddResource(ent, "malt", 0)
		RD_AddResource(ent, "yeast", 0)
		return {}, maxhealth, mass
	end

	   beergens.huge_beer_generator = function( ply, ent, system_type, system_class, model )
		local maxhealth = 400
		local mass = 2000
		RD_AddResource(ent, "energy", 0)
		RD_AddResource(ent, "water", 0)
		RD_AddResource(ent, "beer", 0)
		RD_AddResource(ent, "hops", 0)
		RD_AddResource(ent, "malt", 0)
		RD_AddResource(ent, "yeast", 0)
		return {}, maxhealth, mass
	end
end

local beergens_models = {
        { 'Beer Generator', 'models/props_vehicles/generatortrailer01.mdl', 'beer_generator' },
	{ 'Huge Beer Generator', 'models/props_wasteland/lighthouse_fresnel_light_base.mdl', 'huge_beer_generator' },
	{ 'Barley Extractor', 'models/props_citizen_tech/Firetrap_PropaneCanister01a.mdl', 'barley_extractor' },
	{ 'Huge Barley Extractor', 'models/props_rooftop/chimneypipe_cluster02a.mdl', 'huge_barley_extractor' },
	{ 'Malter', 'models/props_lab/generatorconsole.mdl', 'malter' },
	{ 'Huge Malter', 'models/props_lab/workspace003.mdl', 'malter' },
	{ 'Yeast Gatherer', 'models/props_canal/winch02.mdl', 'yeast_gatherer' },
	{ 'Large Hops Extractor', 'models/props_junk/TrashDumpster01a.mdl', 'large_hops_extractor' },
	{ 'Large Barley Extractor', 'models/props_c17/furnitureStove001a.mdl', 'large_barley_extractor' },
	{ 'Large Malter', 'models/props_lab/servers.mdl', 'large_malter' },
	{ 'Large Yeast Gatherer', 'models/props_wasteland/chimneypipe02b.mdl', 'large_yeast_gatherer' },
	{ 'Hops Extractor', 'models/props_junk/TrashDumpster01a.mdl', 'hops_extractor' },
	{ 'Resource Extractor', 'models/Cranes/crane_frame.mdl', 'resource_extractor' },
}

RD2_ToolRegister( TOOL, beergens_models, nil, "beergens", 30, beergens )
